<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ include file="/commons/pages/taglibs.jsp" %>
<c:set var="app_name" value="器件平台管理系统" />
<c:set var="copyright" value="版权所有 © 安徽力高新能源技术有限公司" />
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>${app_name}</title>
<link rel="stylesheet" type="text/css" href="../jquery-easyui/themes/${themes}/easyui.css">
<link rel="stylesheet" type="text/css" href="../jquery-easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="../styles/demo.css">
<script type="text/javascript" src="../jquery-easyui/jquery.min.js"></script>
<script type="text/javascript" src="../jquery-easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../jquery-easyui/locale/easyui-lang-zh_CN.js"></script>
<script type="text/javascript" src="../scripts/public.js.jsp"></script>
<script type="text/javascript" src="${ctx}/platform/type-info/format"></script>
</head>
<body class="easyui-layout" style="width:100%; height:100%; overflow:hidden">
<!--
<div region="north" split="false" border="true" style="overflow:hidden; height:32px; line-height:32px; color:#fff; background:url(../images/bg.gif) #7f99be repeat-x center 50%;">
  <div style="float:left; color:#fff; font-size:16px; font-weight:bold; padding-left:8px;">${app_name}</div>
  <div style="float:right; padding-right:60px;"><img src="../images/e3d/cpu.png" style="vertical-align:middle"/> <img src="../images/e3d/dip-16-pin.png" style="vertical-align:middle" /> <img src="../images/e3d/lcd.png" style="vertical-align:middle"/> <img src="../images/e3d/led.png" style="vertical-align:middle"/> <img src="../images/e3d/pcb.png" style="vertical-align:middle"/> <img src="../images/e3d/smd-64-pin.png" style="vertical-align:middle"/> <img src="../images/e3d/sot-6-pin.png" style="vertical-align:middle"/> <img src="../images/e3d/tc220.png" style="vertical-align:middle"/> </div>
  <div style="clear:both;"></div>
</div>
-->
<c:set var="real_name" value="：${sessionScope['userInfo'].real_name}" />
<c:set var="root" value="${sysModuleList[0]}" />
<c:set var="children" value="${root._children}" />
<div data-options="region:'west', split:true, border:true" title="欢迎您${real_name}" style="width:180px; padding:0px;" data-options="iconCls:'iconx iconx-home'">
<div class="easyui-accordion"  data-options="fit:true, border:false, animate:true">
  <c:forEach var="cur" items="${children}" varStatus="vs">
    <c:if test="${cur._map.isHasPermissions}">
      <div title="${cur.mod_name}" data-options="iconCls:'iconx ${cur.mod_icon}'" class="combo">
        <ul>
          <c:forEach var="cur1" items="${cur._children}" varStatus="vs1">
            <c:if test="${cur1._map.isHasPermissions}">
              <c:url var="mod_url" value="${cur1.mod_url}">
                <c:param name="mod_code" value="${cur1.mod_code}" />
              </c:url>
              <li onclick="addTab(this, '${mod_url}')"><span class="iconx ${cur1.mod_icon}">&nbsp;</span>${cur1.mod_name}</li>
            </c:if>
          </c:forEach>
        </ul>
      </div>
    </c:if>
  </c:forEach>
</div>
</div>
<div data-options="region:'center'" title="器件平台管理系统">
  <div id="tabs" class="easyui-tabs" data-options="tools:'#tab-tools', fit:true, border:true">
    <div title="欢迎页" data-options="iconCls:'iconx iconx-home'" style="padding:0px; overflow:hidden; background:no-repeat url(${ctx}/images/welcome.png);"></div>
  </div>
  <div id="tab-tools"><a href="#" class="easyui-menubutton" data-options="menu:'#mmThemes', iconCls:'icon-reload'">换肤</a> 
    <!--a href="#" class="easyui-menubutton" menu="#mmHelp" data-options="iconCls:'icon-help'">帮助</a--> 
    <!--a href="#" class="easyui-linkbutton" plain="true" data-options="iconCls:'icon-cancel'" onclick="javascript:$('#mmContext #closeAll').click();">关闭所有标签</a--> 
    <a href="#" class="easyui-linkbutton" data-options="plain:true, iconCls:'icon-cancel'" onclick="javascript:exit();">退出</a></div>
</div>
<div data-options="region:'south', border:false" style="height:26px; line-height:26px; text-align:center; overflow:hidden;" class="accordion">
  <div class="accordion-header">${copyright}</div>
</div>
<!-- 工具栏菜单 -->
<div id="mmThemes" style="width:120px;">
  <div id="themes_default">default</div>
  <div id="themes_gray">gray</div>
  <div id="themes_black">black</div>
  <div id="themes_bootstrap">bootstrap</div>
  <div id="themes_metro">metro</div>
<!--   <div id="themes_cupertino">库比蒂诺</div> -->
<!--   <div id="themes_dark-hive">黑色蜂巢</div> -->
<!--   <div id="themes_pepper-grinder">胡椒研磨机</div> -->
<!--   <div id="themes_sunny">阳光灿烂</div> -->
</div>
<!-- 帮助菜单 --> 
<!--
<div id="mmHelp" style="width:120px;">
  <div data-options="iconCls:'icon-tip'" onclick="javascript:about();">关于本系统...</div>
  <div data-options="iconCls:'icon-no'" onclick="javascript:exit();">退出系统</div>
</div>
--> 
<!-- 右键菜单 -->
<div id="mmContext" class="easyui-menu" style="width:160px;">
  <div id="refresh">刷新</div>
  <div class="menu-sep"></div>
  <div id="close">关闭</div>
  <div id="closeAll">全部关闭</div>
  <div id="closeOthers">除此之外全部关闭</div>
  <div class="menu-sep"></div>
  <div id="closeRight">当前页右侧全部关闭</div>
  <div id="closeLeft">当前页左侧全部关闭</div>
  <div class="menu-sep"></div>
  <div id="exit">退出</div>
</div>
<script type="text/javascript">
$(function(){
	//功能链接变色效果
	$(".easyui-accordion ul li").hover(function (){
		$(this).addClass("hover");
	}, function (){
		$(this).removeClass("hover");
	});
	
	//工具栏菜单绑定换肤
	$('#mmThemes').menu({
	    onClick:function(item){  
	    	$.ajax({
	    		url:'${ctx}/themes/' + (item.id).replace('themes_', ''),
	    		type:'GET',
	    		success: function (){
	    			parent.location.href = '${ctx}/platform/main';
	    		},
	    		error : function (){
	    			$.messager.show({title:'信息提示', timeout:3000, msg:'更换皮肤失败!'});
	    		}
	    	});
	    }  
	});

	//选中皮肤
	$("div[id^='themes_']").each(function(){
		if($(this).attr("id") == "themes_${themes}") {
			$('#mmThemes').menu('setIcon', {
				target: $('#mmThemes').menu('findItem', $(this).text()).target, 
				iconCls:'icon-ok'
			});
		}
	});
	
	//初始化TAB右键菜单
	initTabContextMenu();
	
	//绑定TAB右键菜单事件
    $('#mmContext').menu({
        onClick: function (item) {
            clickMenuItem(item.id);
        }
    });
});

//初始化TAB右键菜单
function initTabContextMenu() {
	
	//双击关闭TAB选项卡
	$(".tabs-inner").dblclick(function(){
		var subtitle = $(this).children(".tabs-closable").text();
		$('#tabs').tabs('close', subtitle);
	});
	
	//为每个选项卡绑定右键
	$(".tabs-inner").bind('contextmenu',function(e){
		$('#mmContext').menu('show', {
			left: e.pageX,
			top: e.pageY
		});
		return false;
	});
}

//右键菜单事件
function clickMenuItem(action){
    var $tabs = $('#tabs').tabs('tabs');
    var $curtab = $('#tabs').tabs('getSelected');
	var titles = [];
	$.each($tabs, function(i, n){
		titles.push($(n).panel('options').title);
	});

    switch (action) {
        case "refresh":
        	var iframe = $curtab.find('iframe')[0];
        	if (iframe && iframe.src) {
        		iframe.contentWindow.location.href = iframe.src;
        	}
            break;
        case "close":
        	if ($curtab.panel('options').closable) {
            	$('#tabs').tabs('close', $curtab.panel('options').title);
        	}
            break;
        case "closeAll":
            $.each(titles, function (i, n) {
            	if ($('#tabs').tabs('getTab', n).panel('options').closable) {
            		$('#tabs').tabs('close', n);
            	}
            });
            break;
        case "closeOthers":
            var title = $curtab.panel('options').title;
            $.each(titles, function (i, n) {
                if (n != title && $('#tabs').tabs('getTab', n).panel('options').closable){
                    $('#tabs').tabs('close', n);
				}
            });
            break;
        case "closeRight":
            var tabIndex = $('#tabs').tabs('getTabIndex', $curtab);
            if (tabIndex == $tabs.length - 1){
                return false;
            }
            $.each(titles, function (i, n) {
                if (i > tabIndex && $('#tabs').tabs('getTab', n).panel('options').closable) {
                	$('#tabs').tabs('close', n);
                }
            });
            break;
        case "closeLeft":
            var tabIndex = $('#tabs').tabs('getTabIndex', $curtab);
            if (tabIndex == 1) {
                return false;
            }
            $.each(titles, function (i, n) {
                if (i < tabIndex && $('#tabs').tabs('getTab', n).panel('options').closable) {
                	$('#tabs').tabs('close', n);
                }
            });
            break;
        case "exit":
            $('#mmContext').menu('hide');
            break;
    }
}

//关于本系统
function about(){
	alert('${app_name}\n\n${copyright}\nPowered By SSM+jQueryEasyUI');
}

//退出系统
function exit(){
	$.messager.confirm('信息确认', '确定要退出系统吗？',function(r){  
		if (r){
			location.href='${ctx}/logout';
		}
	});	
}

//添加标签
function addTab(e, url){
	if (!url) return false;
	var title = $(e).html();
	//var iconCls = $(e).prev("span").attr("class");
    if ($('#tabs').tabs('exists', title)){
    	$('#tabs').tabs('select', title);
        refreshTab({title:title, url:url}); 
    } else {
    	$('#tabs').tabs('add',{
            title: title,
            content: createTabContent(url),
            //iconCls: iconCls,//擦，省了！
            closable: true,
        });
    }
    initTabContextMenu();
}

//生成TAB的content
function createTabContent(src) {
	return '<iframe scrolling="auto" frameborder="0" src="' + src + '" style="width:100%; height:100%; overflow-x:hidden; overflow:auto;"></iframe>';
}

//刷新标签
function refreshTab(cfg){  
    var tab = cfg.title ? $('#tabs').tabs('getTab', cfg.title) : $('#tabs').tabs('getSelected');  
    if(tab && tab.find('iframe').length > 0){  
	    var iframe = tab.find('iframe')[0];  
	    var src = cfg.url || iframe.src;  
	    //ifram.src = refresh_url;  
	    iframe.contentWindow.location.href = src;  
    }  
}
</script>
</body>
</html>